package svc

import (
	"github.com/zeromicro/go-zero/rest"
	"github.com/zeromicro/go-zero/zrpc"
	"house/api/internal/config"
	"house/api/internal/middleware"
	"house/bookingrpc/bookingrpcclient"
	"house/consultrpc/consultrpcclient"
	"house/houserpc/houserpcclient"
	"house/userrpc/userrpcclient"
)

type ServiceContext struct {
	Config              config.Config
	UserRpc             userrpcclient.Userrpc
	HouseRpc            houserpcclient.Houserpc
	BookingRpc          bookingrpcclient.Bookingrpc
	ConsultRpc          consultrpcclient.Consultrpc
	UserAgentMiddleware rest.Middleware
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config:              c,
		UserRpc:             userrpcclient.NewUserrpc(zrpc.MustNewClient(c.UserRpc)),
		HouseRpc:            houserpcclient.NewHouserpc(zrpc.MustNewClient(c.HouseRpc)),
		BookingRpc:          bookingrpcclient.NewBookingrpc(zrpc.MustNewClient(c.BookingRpc)),
		ConsultRpc:          consultrpcclient.NewConsultrpc(zrpc.MustNewClient(c.ConsultRpc)),
		UserAgentMiddleware: middleware.NewUserAgentMiddleware().Handle,
	}
}
